package com.deepexp.servicetest;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.deepexp.servicetest.adapter.AccountAdapter;
import com.deepexp.servicetest.entity.Account;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {
    public Button button;
    public RecyclerView rc_View;
    public AccountAdapter accountAdapter;
    public ArrayList<Account> accounts;
    public Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            accountAdapter.setData(accounts);
        }
    };

    public EditText et_Phone, et_Password;

    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_servicedata_layout);
        accounts = new ArrayList<>();
        accountAdapter = new AccountAdapter(this);
        accountAdapter.setData(accounts);
        et_Phone = findViewById(R.id.et_Phone);
        et_Phone.setAutofillHints("输入手机号");
        et_Password = findViewById(R.id.et_Password);
        et_Password.setAutofillHints("输入密码");
        rc_View = findViewById(R.id.rc_View);
        button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                getData();
                SharedPreferences sp=getSharedPreferences("user", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor=sp.edit();
                editor.putString("username",et_Phone.getText().toString());
                editor.putString("password",et_Password.getText().toString());
                editor.apply();
            }
        });
        rc_View.setLayoutManager(new LinearLayoutManager(this));
        rc_View.setAdapter(accountAdapter);

    }

// /   public void getData() {
//        Call<List<Account>> call = RequestUtils.getInstance(MainActivity.this).getApiService().getAccount();
//        call.enqueue(new Callback<List<Account>>() {
//            @Override
//            public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
//                accounts.clear();
//                if (response.body() != null) {
//                    List<Account> accounts_ls = response.body();
//                    for (int i = 0; i < accounts_ls.size(); i++) {
//                        accounts.add(accounts_ls.get(i));
//                    }
//                }
//                handler.sendEmptyMessage(0);
//                Log.i("打印获得的值：正常", "" + response);
//            }
//
//            @Override
//            public void onFailure(Call<List<Account>> call, Throwable t) {
//                Log.i("打印获得的值: 报错", "" + t.getMessage());
//            }
//        });
//    }
}